from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Any, Dict, Iterator


@dataclass
class TextSegment:
    text: str             # 存放切割文本
    meta: Dict[str, Any]  # 存储分割器的特定元数据
    splitter_id: str      # 标识来自哪个分割器

class TextSplitter(ABC):
    def __init__(self):
        super().__init__()
        
    @property
    def splitter_id(self) -> str:
        return self.__class__.__name__  # 默认使用类名作为标识
        
    @abstractmethod
    def split(self, text: str, extra_kwargs: Dict = None) -> Iterator[TextSegment]:
        raise NotImplementedError